package org.edu.modules.sxjy.controller;

import com.alibaba.fastjson.JSON;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.edu.common.api.vo.Result;
import org.edu.common.aspect.annotation.AutoLog;
import org.edu.modules.sxjy.common.noresubmit.CacheLock;
import org.edu.modules.sxjy.entity.VeBaseDictData;
import org.edu.modules.sxjy.entity.VeBaseDictionary;
import org.edu.modules.sxjy.entity.VeBaseFaculty;
import org.edu.modules.sxjy.entity.VeBaseGrade;
import org.edu.modules.sxjy.entity.VeBaseStudent;
import org.edu.modules.sxjy.entity.VeBaseSysConfig;
import org.edu.modules.sxjy.entity.VeBaseTeacher;
import org.edu.modules.sxjy.feign.VeCommonClient;
import org.edu.modules.sxjy.service.CacheKeyGenerator;
import org.edu.modules.sxjy.service.impl.CacheKeyGeneratorImp;
import org.edu.modules.sxjy.utils.PageResponseResult;
import org.edu.modules.sxjy.utils.PagingUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author leidq
 * @create 2022-04-08 10:15
 */
@Api(tags={"公共类"})
@RestController
@RequestMapping("/sxjy/common")
@ApiSort(60)
@Component
public class CommonController
{
    private static final Logger log = LoggerFactory.getLogger(CommonController.class);
    @Autowired
    private VeCommonClient veCommonClient;

    @Bean
    public CacheKeyGenerator cacheKeyGenerator()
    {
        return new CacheKeyGeneratorImp();
    }

    @AutoLog("公共类-获取所有学制")
    @ApiOperation(value="获取所有学制", notes="公共类-获取所有学制")
    @GetMapping({"/queryXueZhiList"})
    Result<?> queryXueZhiList(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId)
    {
        return this.veCommonClient.queryXueZhiList(interfaceUserId);
    }

    @AutoLog("公共类-获取所有年级")
    @ApiOperation(value="获取所有年级", notes="公共类-获取所有年级")
    @GetMapping({"/queryGradeList"})
    Result<?> queryGradeList(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId)
    {
        return this.veCommonClient.queryGradeList(interfaceUserId);
    }

    @AutoLog("公共类获取所有院系")
    @ApiOperation(value="获取所有院系", notes="公共类-获取所有院系")
    @GetMapping({"/queryFacultyList"})
    Result<?> queryFacultyList(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId)
    {
        return this.veCommonClient.queryFacultyList(interfaceUserId);
    }

    @AutoLog("公共类-根据院系id获取所有专业")
    @ApiOperation(value="根据院系id获取所有专业", notes="公共类-根据院系id获取所有专业")
    @GetMapping({"/querySpecialtyListByFalId"})
    Result<?> querySpecialtyListByFalId(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId, @RequestParam(name="falId", required=true) Integer falId)
    {
        return this.veCommonClient.querySpecialtyListByFalId(interfaceUserId, falId);
    }

    @AutoLog("公共类-根据专业id获取所有班级")
    @ApiOperation(value="根据专业id获取所有班级", notes="公共类-根据专业id获取所有班级")
    @GetMapping({"/queryBanJiListBySpecId"})
    Result<?> queryBanJiListBySpecId(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId, @RequestParam(name="specId", required=true) Integer specId)
    {
        return this.veCommonClient.queryBanJiListBySpecId(interfaceUserId, specId);
    }

    @AutoLog("公共类-获取所有部门信息")
    @ApiOperation(value="获取所有部门信息", notes="公共类-获取所有部门信息")
    @GetMapping({"/queryDepartmentList"})
    Result<?> queryDepartmentList(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId)
    {
        return this.veCommonClient.queryDepartmentList(interfaceUserId);
    }

    @AutoLog("公共类-获取所有部门信息和部门下的老师信息")
    @ApiOperation(value="获取所有部门信息和部门下的老师信息", notes="公共类-获取所有部门信息和部门下的老师信息")
    @GetMapping({"/queryDepartmentAndTeacherList"})
    Result<?> queryDepartmentAndTeacherList(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId)
    {
        return this.veCommonClient.queryDepartmentAndTeacherList(interfaceUserId);
    }

    @AutoLog("公共类-获取所有校区信息")
    @ApiOperation(value="获取所有校区信息", notes="公共类-获取所有校区信息")
    @GetMapping({"/queryCampusList"})
    Result<?> queryCampusList(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId)
    {
        return this.veCommonClient.queryCampusList(interfaceUserId);
    }

    @AutoLog("公共类-根据老师的user_id查找老师的信息")
    @ApiOperation(value="根据老师的user_id查找老师的信息", notes="公共类-根据老师的user_id查找老师的信息")
    @GetMapping({"/queryTeacherByUserId"})
    Result<?> queryTeacherByUserId(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId, @RequestParam(name="userId", required=true) String userId)
    {
        return this.veCommonClient.queryTeacherByUserId(interfaceUserId, userId);
    }

    @AutoLog("公共类-根据老师的工号查找老师的信息")
    @ApiOperation(value="根据老师的工号查找老师的信息", notes="公共类-根据老师的工号查找老师的信息")
    @GetMapping({"/queryTeacherByGH"})
    Result<?> queryTeacherByGH(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId, @RequestParam(name="gh", required=true) String gh)
    {
        return this.veCommonClient.queryTeacherByGH(interfaceUserId, gh);
    }

    @AutoLog("公共类-根据学生userId查找学生信息")
    @ApiOperation(value="根据学生userId查找学生信息", notes="公共类-根据学生userId查找学生信息")
    @GetMapping({"/queryStudentByUserId"})
    Result<?> queryStudentById(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId, @RequestParam(name="userId", required=true) String userId)
    {
        return this.veCommonClient.queryStudentById(interfaceUserId, userId);
    }

    @AutoLog("公共类-获取所有学期信息")
    @ApiOperation(value="获取所有学期信息", notes="公共类-获取所有学期信息")
    @GetMapping({"/querySemesterList"})
    Result<?> querySemesterList(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId)
    {
        return this.veCommonClient.querySemesterList(interfaceUserId);
    }

    @AutoLog("公共类-获取所有省份信息")
    @ApiOperation(value="获取所有省份信息", notes="公共类-获取所有省份信息")
    @GetMapping({"/queryProvinceList"})
    Result<?> queryProvinceList(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId)
    {
        return this.veCommonClient.queryProvinceList(interfaceUserId);
    }

    @AutoLog("公共类-根据省份id获取所有市级信息")
    @ApiOperation(value="根据省份id获取所有市级信息", notes="公共类-根据省份id获取所有市级信息")
    @GetMapping({"/queryCityListByProvinceId"})
    Result<?> queryCityList(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId, @RequestParam(name="provinceId", required=true) Integer provinceId)
    {
        return this.veCommonClient.queryCityList(interfaceUserId, provinceId);
    }

    @AutoLog("公共类-根据市级id获取所有县级信息")
    @ApiOperation(value="根据市级id获取所有县级信息", notes="公共类-根据市级id获取所有县级信息")
    @GetMapping({"/queryCountyListByCityId"})
    Result<?> queryCountyList(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId, @RequestParam(name="cityId", required=true) Integer cityId)
    {
        return this.veCommonClient.queryCountyList(interfaceUserId, cityId);
    }

    @AutoLog("公共类-教师信息-列表查询")
    @ApiOperation(value="教师信息-列表查询", notes="公共类-教师信息-列表查询")
    @GetMapping({"/getTeacherList"})
    PageResponseResult getTeacherList(@RequestParam(name="interfaceUserId", required=false) String interfaceUserId, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize)
    {
        Result<?> teacherList = this.veCommonClient.getTeacherList("09d5e1e7f9b049008eee645c783a1d67");

        List<VeBaseTeacher> veBaseTeacherList = new ArrayList();

        List<Object> teacherListResult = (List)teacherList.getResult();
        for (Object o : teacherListResult)
        {
            Map map = (Map)o;
            String s = JSON.toJSONString(map);
            VeBaseTeacher veBaseTeacher = (VeBaseTeacher)JSON.parseObject(s, VeBaseTeacher.class);
            VeBaseTeacher veBaseTeachers = new VeBaseTeacher();
            if ((veBaseTeacher.getId() != null) && (!"".equals(veBaseTeacher.getId()))) {
                veBaseTeachers.setId(veBaseTeacher.getId());
            }
            if ((veBaseTeacher.getGh() != null) && (!"".equals(veBaseTeacher.getGh()))) {
                veBaseTeachers.setGh(veBaseTeacher.getGh());
            }
            if ((veBaseTeacher.getXm() != null) && (!"".equals(veBaseTeacher.getXm()))) {
                veBaseTeachers.setXm(veBaseTeacher.getXm());
            }
            if ((veBaseTeacher.getUserId() != null) && (!"".equals(veBaseTeacher.getUserId()))) {
                veBaseTeachers.setUserId(veBaseTeacher.getUserId());
            }
            if ((veBaseTeacher.getSfzjh() != null) && (!"".equals(veBaseTeacher.getSfzjh()))) {
                veBaseTeachers.setSfzjh(veBaseTeacher.getSfzjh());
            }
            if ((veBaseTeacher.getDepName() != null) && (!"".equals(veBaseTeacher.getDepName()))) {
                veBaseTeachers.setDepName(veBaseTeacher.getDepName());
            }
            if ((veBaseTeacher.getBzlbm() != null) && (!"".equals(veBaseTeacher.getBzlbm()))) {
                veBaseTeachers.setBzlbm(veBaseTeacher.getBzlbm());
            }
            if ((veBaseTeacher.getJzglbm() != null) && (!"".equals(veBaseTeacher.getJzglbm()))) {
                veBaseTeachers.setJzglbm(veBaseTeacher.getJzglbm());
            }
            veBaseTeacherList.add(veBaseTeachers);
        }
        Object pageData = PagingUtils.getPageData(veBaseTeacherList, pageNo, pageSize);
        List<VeBaseTeacher> veBaseTeacherListx = (List)((Map)pageData).get("data");
        int totalPage = ((Integer)((Map)pageData).get("totalPage")).intValue();
        return new PageResponseResult(pageNo, totalPage, veBaseTeacherList.size(), Result.OK(veBaseTeacherListx));
    }

    @AutoLog("教师信息-分页列表查询")
    @ApiOperation(value="教师信息-分页列表查询", notes="教师信息-分页列表查询")
    @GetMapping({"/getTeacherPageList"})
    public Result<?> getTeacherPageList(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId, @RequestParam(name="gh", required=false) String gh, @RequestParam(name="xm", required=false) String xm, @RequestParam(name="sfzjh", required=false) String sfzjh, @RequestParam(name="depId", required=false) Integer depId, @RequestParam(name="jyzId", required=false) Integer jyzId, @RequestParam(name="bzlbm", required=false) String bzlbm, @RequestParam(name="jzglbm", required=false) String jzglbm, @RequestParam(name="teacherIds", required=false) String teacherIds, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize)
    {
        return this.veCommonClient.getTeacherPageList("09d5e1e7f9b049008eee645c783a1d67", gh, xm, sfzjh, depId, jyzId, bzlbm, jzglbm, teacherIds, pageNo, pageSize);
    }

    @AutoLog("学生信息-分页列表查询")
    @ApiOperation(value="学生信息-分页列表查询", notes="学生信息-分页列表查询")
    @GetMapping({"/getStudentPageList"})
    public Result<?> getStudentPageList(VeBaseStudent veBaseStudent, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize)
    {
        return this.veCommonClient.getStudentPageList(veBaseStudent, pageNo, pageSize);
    }

    @AutoLog("公共类-根据code编码查找数据字典信息")
    @ApiOperation(value="根据code编码查找数据字典信息", notes="公共类-根据code编码查找数据字典信息")
    @GetMapping({"/queryDictionaryByCode"})
    Result<?> queryDictionaryByCode(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId, @RequestParam(name="code", required=true) String code)
    {
        return this.veCommonClient.queryDictionaryByCode(interfaceUserId, code);
    }

    @AutoLog("公共类-根据modelCode查找字典数据信息")
    @ApiOperation(value="根据modelCode查找字典数据信息", notes="公共类-根据modelCode查找字典数据信息")
    @GetMapping({"/queryDictDataByModelCode"})
    Result<?> queryDictDataByModelCode(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId, @RequestParam(name="modelCode", required=true) String modelCode, @RequestParam(name="code", required=false) String code)
    {
        return this.veCommonClient.queryDictDataByModelCode(interfaceUserId, modelCode, code);
    }

    @AutoLog("根据modelCode和title查找字典数据信息")
    @ApiOperation(value="根据modelCode和title查找字典数据信息", notes="根据modelCode和title查找字典数据信息")
    @GetMapping({"/queryDictDataByModelCodeTitle"})
    public Result<?> queryDictDataByModelCodeTitle(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId, @RequestParam(name="modelCode", required=true) String modelCode, @RequestParam(name="title") String title)
    {
        return this.veCommonClient.queryDictDataByModelCodeTitle(interfaceUserId, modelCode, title);
    }

    @AutoLog("公共类-数据字典数据-查询菜单")
    @ApiOperation(value="数据字典数据-查询菜单", notes="公共类-数据字典数据-查询菜单")
    @GetMapping({"/queryDictionaryTreeList"})
    Result<?> queryDictionaryTreeList(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId)
    {
        return this.veCommonClient.queryDictionaryTreeList(interfaceUserId);
    }

    @AutoLog("公共类-数据字典管理-新增信息")
    @ApiOperation(value="数据字典管理-新增信息", notes="公共类-数据字典管理-新增信息")
    @PostMapping({"/addVeBaseDictionary"})
    @CacheLock(prefix="redisLock.test", expire=1)
    Result<?> addVeBaseDictionary(@RequestBody VeBaseDictionary veBaseDictionary)
    {
        return this.veCommonClient.addVeBaseDictionary(veBaseDictionary);
    }

    @AutoLog("公共类-数据字典管理-修改信息")
    @ApiOperation(value="数据字典管理-修改信息", notes="公共类-数据字典管理-修改信息")
    @PutMapping({"/editVeBaseDictionary"})
    @CacheLock(prefix="redisLock.test", expire=1)
    Result<?> editVeBaseDictionary(@RequestBody VeBaseDictionary veBaseDictionary)
    {
        return this.veCommonClient.editVeBaseDictionary(veBaseDictionary);
    }

    @AutoLog("公共类-数据字典管理-通过id删除")
    @ApiOperation(value="数据字典管理-通过id删除", notes="公共类-数据字典管理-通过id删除")
    @DeleteMapping({"/deleteVeBaseDictionary"})
    Result<?> deleteVeBaseDictionary(@RequestParam(name="id", required=true) String id, @RequestParam(name="interfaceUserId", required=true) String interfaceUserId)
    {
        return this.veCommonClient.deleteVeBaseDictionary(id, interfaceUserId);
    }

    @AutoLog("公共类-数据字典数据-新增信息")
    @ApiOperation(value="数据字典数据-新增信息", notes="公共类-数据字典数据-新增信息")
    @PostMapping({"/addVeBaseDictData"})
    @CacheLock(prefix="redisLock.test", expire=1)
    Result<?> addVeBaseDictData(@RequestBody VeBaseDictData veBaseDictData)
    {
        return this.veCommonClient.addVeBaseDictData(veBaseDictData);
    }

    @AutoLog("公共类-数据字典数据-修改信息")
    @ApiOperation(value="数据字典数据-修改信息", notes="公共类-数据字典数据-修改信息")
    @PutMapping({"/editVeBaseDictData"})
    @CacheLock(prefix="redisLock.test", expire=1)
    Result<?> editVeBaseDictData(@RequestBody VeBaseDictData veBaseDictData)
    {
        return this.veCommonClient.editVeBaseDictData(veBaseDictData);
    }

    @AutoLog("公共类-数据字典数据-通过id删除")
    @ApiOperation(value="数据字典数据-通过id删除", notes="公共类-数据字典数据-通过id删除")
    @DeleteMapping({"/deleteVeBaseDictData"})
    Result<?> deleteVeBaseDictData(@RequestParam(name="id", required=true) String id, @RequestParam(name="interfaceUserId", required=true) String interfaceUserId)
    {
        return this.veCommonClient.deleteVeBaseDictData(id, interfaceUserId);
    }

    @AutoLog("操作日志-分页列表查询(实习调用)")
    @ApiOperation(value="操作日志-分页列表查询(实习调用)", notes="操作日志-分页列表查询(实习调用)")
    @GetMapping({"/querySysLogPageListSX"})
    public Result<?> querySysLogPageListSX(@RequestParam(name="interfaceUserId", required=true) String interfaceUserId, @RequestParam(name="userName", required=false) String userName, @RequestParam(name="ip", required=false) String ip, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize)
    {
        return this.veCommonClient.querySysLogPageListSX(interfaceUserId, userName, ip, pageNo, pageSize);
    }

    @AutoLog("年级信息-分页列表查询")
    @ApiOperation(value="年级信息-分页列表查询", notes="年级信息-分页列表查询")
    @GetMapping({"/getGradePageList"})
    public Result<?> getGradePageList(VeBaseGrade veBaseGrade, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req)
    {
        return this.veCommonClient.getGradePageList(veBaseGrade, pageNo, pageSize, req);
    }

    @AutoLog("院系信息(专业部)-分页列表查询")
    @ApiOperation(value="院系信息(专业部)-分页列表查询", notes="院系信息(专业部)-分页列表查询")
    @GetMapping({"/getFacultyPageList"})
    public Result<?> getFacultyPageList(VeBaseFaculty veBaseFaculty, @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, HttpServletRequest req)
    {
        return this.veCommonClient.getFacultyPageList(veBaseFaculty, pageNo, pageSize, req);
    }

    @AutoLog("系统配置列表查询")
    @ApiOperation(value="系统配置列表查询", notes="系统配置列表查询")
    @GetMapping({"/querySysConfigList"})
    public Result<?> querySysConfigList(VeBaseSysConfig veBaseSysConfig)
    {
        return this.veCommonClient.querySysConfigList(veBaseSysConfig);
    }
}

